<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
	<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
	<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ include file="../../common/base.jsp"%>
<%
	response.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
<link href="${path }/dist/css/bootstrap.css" rel="stylesheet">
<link href="${path }/dist/css/bootstrap-overrides.css" rel="stylesheet">

<!-- Button -->
<link href="${path }/dist/css/compiled/elements.css" rel="stylesheet">
<!-- libraries -->
<link rel="stylesheet" type="text/css"  href="${path }/dist/css/font-awesome.css">
<!-- this -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/app.css">
<link href='${path }/dist/css/zTreeStyle/zTreeStyle.css' rel='stylesheet' />
<link href="${path }/dist/css/bootstrap-datetimepicker.min.css" rel="stylesheet"><%--时间日期工具 --%>
<!-- 右键菜单插件 -->
<link rel="stylesheet" type="text/css" href="${path }/dist/css/smartMenu.css">

<link rel="stylesheet" type="text/css" href="${path }/back/ifrom.css">
<script src="${path }/dist/js/jquery.min.js"></script>
<script src='${path }/dist/js/bootstrap.min.js'></script>
<script src="${path }/dist/js/theme.js"></script>
<script src='${path }/dist/js/jquery-smartMenu.js'></script>
<script src='${path }/dist/js/jquery.ztree.core-3.5.js'></script>
<script src='${path }/dist/js/jquery.ztree.excheck-3.5.js'></script>
<script src='${path }/dist/js/jquery.ztree.exedit-3.5.js'></script>
<script src="${path }/dist/js/bootstrap-datetimepicker.min.js"></script>
<script src="${path }/dist/js/bootstrap-datetimepicker.zh-CN.js"></script>

<style>
table tr>td.title{
		width: 85px;
		padding-right: 0px;
	}
.left_tree{
	height: 430px;
	overflow: auto;
	border: 1px solid #ccc;
	 border-radius: 5px;
}
#pad-wrapper h3{
	font-family: "黑体";
}
#library_from_table th{
	padding: 10px 0;
	cursor: pointer;
}
#library_from_table input,
#library_from_table input:hover,
#library_from_table input:focus{
	border-left: none !important;
	border-right: none !important;
	border-top: none !important;
	background-color: transparent !important;
	color: #000 !important;
	box-shadow:none !important;
}
#library_from_table input[readonly],#node_tbody input[readonly]{
	cursor: pointer;
	
}
.table tr>td{
	padding:  2px 5px;
	max-width: 100px;
	height: 20px;
}
.table tr>td select{
	width: 100%;
}
.panel-body span.tip{
	float: right;
}
.menuContent {padding-top: 10px;border: 1px solid #617775;background: #f0f6e4;width:160px;height:260px;overflow-y:scroll;overflow-x:auto;}
.btn-group-vertical{
	width: 100%;
}
i{
	margin-right: 5px;
}
.jumbotron{
	padding-top: 5px;
	padding-bottom: 5px;
}
.tip{
	text-align: right;
	font-size: 12px;
	color: #ccc;
}
</style>
</head>
<body>


<div class="container-fluid" style="padding: 0 50px 0 50px;">
	<div class="row head">
	<div class="col-sm-12">
			<h3>资产出库<em><small>编辑资产时切勿刷新页面，以免造成数据丢失</small></em></h3>
			</div>
	</div>
	<hr>
	<form action="${path}/back/assetsMS!sevaReceipt" method="post" id="library_from" target="curWindow">
	<div class="row">
		<div class="panel panel-default">
			<div class="jumbotron" style="text-align: center;">
				  <h2>福建XXX公司有限公司<%-- <small>单据号：<span >单据号</span></small> --%></h2>
				  <p>出库单</p>
			</div>
			
		<div class="panel-body" style="padding: 0px;">
				<table id='library_from_table'>
					<tbody>
						<tr>
							<td>制单人</td>
							<td><input type="text"  class="form-control input-sm" value="${user.user_account }" disabled="disabled"/></td>
						</tr>
						<tr>
							<td>单据号</td>
							<td><input type="text" name='receiptBean.no' class="form-control input-sm" value="${receipt_no }"/></td>
							<td>领用日期:</td>
							<td><input type="text" class="form-control input-sm form_datetime" name="receiptBean.receipt_data" 
								readonly="readonly" value="<fmt:formatDate value="${date}" pattern="yyyy-MM-dd"/>"/></td>
							<td rowspan="2">
								备注
							</td>
							<td rowspan="2">
								<input type="text" name='receiptBean.receipt_remark' class="form-control" value="[福建XXX公司有限公司 ] 出库单据"/>
							</td>
							<td rowspan="2">
								<button type="button" class="btn btn-success" id="save_all"><i class="icon-save"></i>保存单据</button>
		  						<button type="button" class="btn btn-default" id="clear_list"><i class="icon-repeat"></i>清空</button>
							</td>
						</tr>
						<tr>
							<td>领用部门：</td>
							<td><input type="text" class="form-control input-sm" name="dept_name" readonly="readonly"/><input type="hidden" name='receiptBean.dept_id'/></td>
							<td class="title">领用人：</td>
							<td><input type="text" class="form-control input-sm" name="receiptBean.staff_name" /></td>
							
						</tr>
						
					</tbody>
				</table>
				<span class='tip'>右键点击下面表格进行增加记录</span>
			<div class="row" style="margin-bottom: 10px;margin: 0px;">
				
				<div class="col-sm-12" style="overflow-x: auto;">
					<div style="height: 200px;">
						<table class="table table-striped" id='add_edit_List'>
							<thead>
									<tr id="table_title" class="table_title">
										<th class="sortable" width="100px;"><span>资产编号</span ></th>
										<th class="sortable" ><span class="line"></span><span>资产分类</span ></th>
										<th class="sortable" ><span class="line"></span><span >资产名称</span></th>
										<th class="sortable" ><span class="line"></span><span >资产规格</span></th>
										<th class="sortable" ><span class="line"></span><span >资产单价</span></th>
										<th class="sortable" ><span class="line"></span><span >购置日期</span></th>
										<th class="sortable" width="50px"><span class="line"></span><span >数量</span></th>
										<th class="sortable" ><span class="line"></span><span >备注</span></th>
									</tr>
								</thead>
								<tbody id="node_tbody" >
									<tr data-number=''>
										<td><input type='text' id='add_row' class='form-control input-sm' /></td>
									</tr>
								</tbody>
						</table>
					</div>
				</div>
				
			
			</div>
		</div>
	</div>
	</form>
	</div>
</div>
 <div id="dept_nameMenu" class="menuContent" style="display:none; position: absolute;">
	<ul id="dept_nametree" class="ztree menutree" style=""></ul>
</div>
<iframe src="${path }/back/assetsMS!search_ifrom" id="assetsMenu" 
	class="menuContent" style="display:none; position: absolute;width: 800px;height: 280px;">
</iframe>
	<script type="text/javascript">
	 Array.prototype.indexOf = function(val) {
         for (var i = 0; i < this.length; i++) {
             if (this[i] == val) return i;
         }
         return -1;
     };
     Array.prototype.remove = function(val) {
         var index = this.indexOf(val);
         if (index > -1) {
             this.splice(index, 1);
         }
     };
		window.name = "curWindow";
		var setting_dept = {
				view: {
					selectedMulti: false,//多选
					showLine: true,
					nameIsHTML: true
				}, callback : {
					beforeClick : dept_nametree,
				},data:{
					simpleData:{
						enable: true,
					}
				}
			};
		var receiptData=[
		                [
		                 {text: "删除", func:remove_tr },
		                ]
		               ];
		var tr_count=0;
		var select_number=new Array();
		function remove_tr(){
			if(confirm("确认删除这条吗？")){
				alert($(this).data("number"));
				select_number.remove($(this).data("number"));
				$(this).remove();
				
			}
		}
		//选择部门   部门树子节点被点击
		function dept_nametree(treeId, treeNode){
			if(treeNode.isParent){
				return true;
			}else{
				$("input[name='dept_name']").val(treeNode.name);
				$("input[type='hidden'][name='receiptBean.dept_id']").val(treeNode.id);
			}
			return true;
		}
		//清空table 输入的数据
		function clear_table(){
			$("#row_form input[type='text'][data-close]").each(function(){
				$(this).val("");
			});
			$("input[data-default]").each(function(){
				if($(this).data('default')!=null&&$(this).data('default')!="")
				$(this).val($(this).data('default'));
			});
		}
	$(document).ready(function() {
		//获取部门树
		saveURL = "${path}/back/tree!deptTree?date="+new Date()+"";
		jQuery.post(saveURL,null,function(jsonData){
			$.fn.zTree.init($("#dept_nametree"),setting_dept,jsonData);
		},"json");
		$("input[name='dept_name']").bind("focus",{id:"#dept_nameMenu"},function(e){
			var cityObj = $(this);
			var cityOffset = cityObj.offset();
			$(e.data.id+"").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
			$("body").bind("mousedown",{id:e.data.id}, onBodyDown);
		});
		add_row_input();
		$("#add_row").bind("focus",{id:"#assetsMenu"},getassets);
		$("#add_row").keyup(function(){
			$("#assetsMenu").attr('src','${path }/back/assetsMS!search_ifrom?select_number='+$(this).val()+"&not_number="+select_number.join('\',\'')+"&maxrecord=30");
		});
		$("#save_all").click(function(){
			if($("#node_tbody").find("tr").length>1){//至少有一行数据才可以添加
				var formDom=$(this).closest("form");
				formDom.submit();
				window.returnValue="添加成功";
				window.close();
			}else{
				alert("至少一行数据");
			}
		});
		$("#clear_list").click(function(){
			alert(select_number);
		});
	});
	//删除当然输入框行，并对这行重新生成DOM
	function remove_add_row_input(data){
		var obj=$("#add_row").unbind("focus",getassets);
		var tr_obj=$("#add_row").parent().parent().empty();
		tr_obj.data("number",data.data("number"));
		
		select_number.push(data.data("number"));
		data.find("td").each(function(){
			var td_obj=$("<td></td>").appendTo(tr_obj);
			var input_obj=$("<input type='text' value='"+$(this).html()
					+ "' class='form-control input-sm' readonly/>").appendTo(td_obj);
			if($(this).data("name")!=null&&$(this).data("name")!=""){
				input_obj.attr('name',"receiptdetailslist["+(tr_count)+"]."+$(this).data("name"));
			}
		});
		var input_obj=$("<input type='hidden' value='"+data.data("id")+"' name='receiptdetailslist["+tr_count+"].assets_id'/>").appendTo(tr_obj);

		tr_count++;
		$.smartMenu.remove();
		//执行完成 在加入一个input id="add_row" 的输入用于新增
		add_row_input();
		$("#node_tbody tr:not(:last)").smartMenu(receiptData,{name:"receiptmenu"});
		hidetree('#assetsMenu');
	}
	//在增加一个行数用于新增记录
	function add_row_input(){
		if($("#node_tbody").find('#add_row').size()==0){
			var tr_obj=$("<tr data-number=''></tr>").appendTo($("#node_tbody"));
			var td_obj=$("<td></td>").appendTo(tr_obj);
			var input_obj=$("<input type='text' id='add_row' class='form-control input-sm'/>").appendTo(td_obj);
			$("#add_row").bind("focus",{id:"#assetsMenu"},getassets);
		}
	}
	function getassets(e){
		//展开列表
		var cityObj = $(this);
		var cityOffset = cityObj.offset();
		$(e.data.id+"").css({left:cityOffset.left + "px", top:cityOffset.top + cityObj.outerHeight() + "px"}).slideDown("fast");
		$("body").bind("mousedown",{id:e.data.id}, onBodyDown);
		$(e.data.id+"").attr('src','${path }/back/assetsMS!search_ifrom?select_number='+$(this).val()+"&not_number="+select_number.join('\',\'')+"&maxrecord=30");
	}
	//时间日期
	$(".form_datetime").datetimepicker({format: 'yyyy-mm-dd',language:  'zh-CN',weekStart: 1,
        todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 2,
		forceParse: 0,
        showMeridian: 1,
        minView: 2,
        pickerPosition:"bottom-left"});
	//判断表单导游data-vail 属性是否为空
	function fromisnotnull(fromdom){
		var  pass =true;
		$("input[type='text'][data-vail]",fromdom).each(function(){
			if($(this).val()==null||$(this).val()==""){
				alert("红色为必填项");
				pass =false;
				return false;
			}
		});
		return pass;
	}
	function onBodyDown(evetnt){
		if(!($(evetnt.target).closest(evetnt.data.id).length>0)){
			hidetree(evetnt.data.id);
		}
	}
	//解除 body绑定
	function hidetree(id){
		$(id+"").fadeOut("fast");
		$("body").unbind("mousedown",onBodyDown);
	}


	
	</script>
		<c:if test="${tip!=null }">
<script type="text/javascript">
 alert('${tip}');
</script>
</c:if>
</body>
</html>
<%--	alert(1);

		    var c = $(window.parent.document.body) 
		    //麻烦的方法：
		    //var c = $($(window).eq(0)[0].parent.document).find('body'); //，忘了可以用前面的方法了
		    c.bind('beforeunload', function(e) {    
		        // Mozilla takes the
		        alert(1);
		    }); --%>